﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    class SentenceNumberToken
    {
        internal static void ParseLanguage(GPSData gpsData, System.Collections.Queue q)
        {
            String sentNumToken = (string)q.Dequeue();
            int sentNum = 0;
            try
            {
                if(sentNumToken.Length>0)
                    sentNum = int.Parse(sentNumToken);
            }
            catch { }
            if (sentNum > 1)
            {
                if (sentNum != gpsData.SentenceNumber + 1)
                {
                    throw new GSVOutOfOrderException();
                }
            }

            gpsData.SetSentenceNumber(sentNum);

            switch (gpsData.MessageType)
            {
                case MessageType.GPGSV:
                    SatelliteCountToken.ParseLanguage(gpsData, q);
                    break;
                default:
                    throw new InvalidLanguageException("How did you get here?");
            }

        }
    }
}
